import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;



public class Test {
    public static class Node {
        public int a; //价格
        public int b; //最大交易数
    }

    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        Node[] node = new Node[10];
        int count = 0;  //交易总数
        for (int i = 0; i < n; i++) {
            node[i] = new Node();
            node[i].a = scanner.nextInt();
            node[i].b = scanner.nextInt();
            count += node[i].b;
        }

        Arrays.sort(node, 0, n - 1, new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                return o1.a - o2.a;
            }
        });

        int cnt = 0,k = 0;
        for (int i = 0; i < n; i++) {
            if (cnt + node[i].b < count-cnt) {
                cnt += node[i].b;
                k++;
            }else {
                break;
            }
        }

        int sum1 = 0, sum2 = 0;
        for(int i = 0; i < n; i++) {
            if(i<k) {

            }
        }

        scanner.close();
    }
}
